﻿using System;
using System.Collections.Generic;
using TabbedTemplate.Views;
using Xamarin.Forms;

namespace TabbedTemplate.Services
{
    public class PunchPageActivationService : IPunchPageActivationService
    {
        /// <summary>
        /// 
        /// </summary>
        private Dictionary<string, Type> pageKeyTypeDictionary =
            new Dictionary<string, Type>
            {
                [ContentNavigationConstant.PunchPage] = typeof(PunchPage),
                [ContentNavigationConstant.StorePunchesPage] = typeof(StorePunchesPage),
                [ContentNavigationConstant.IndexPage] = typeof(IndexPage),
                [ContentNavigationConstant.QueryPage] = typeof(QueryPage),
                [ContentNavigationConstant.QueryResultPage] = typeof(QueryResultPage),
                [ContentNavigationConstant.StoreCollectionsPage] = typeof(StoreCollectionsPage),
                [ContentNavigationConstant.QueryResultPage] = typeof(QueryResultPage),
                [ContentNavigationConstant.CityLocations] = typeof(CityLocations),
                [ContentNavigationConstant.NewIndexPage] = typeof(NewIndexPage),
                [ContentNavigationConstant.PunchViewPage] = typeof(PunchViewPage),
                [ContentNavigationConstant.StoreCollectionsPage] = typeof(StoreCollectionsPage),
                [ContentNavigationConstant.SyncPage] = typeof(SyncPage),
                [ContentNavigationConstant.MyPunchesPage] = typeof(MyPunchesPage),
                [ContentNavigationConstant.DrawPicPage] = typeof(DrawPicPage)
            };
        /// <summary>
        /// 缓存
        /// </summary>
        private Dictionary<string, ContentPage> cache =
            new Dictionary<string, ContentPage>();
        /// <summary>
        /// 激活
        /// </summary>
        /// <param name="pageKey">页面键</param>
        /// <returns></returns>
        public ContentPage Activate(string pageKey) =>
            cache.ContainsKey(pageKey)
                ? cache[pageKey]
                : cache[pageKey] =
                    (ContentPage)Activator.CreateInstance(
                        pageKeyTypeDictionary[pageKey]);

    }
}
